# Maintainer: @naveen521kk on Github, Naveen M K <naveen@syrusdark.website>

_realname=manim
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.6.0
pkgrel=1
pkgdesc="Animation engine for explanatory math videos (community edition) (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url='https://www.manim.community'
license=('MIT' 'custom')
depends=(
  "${MINGW_PACKAGE_PREFIX}-python"
  "${MINGW_PACKAGE_PREFIX}-ffmpeg"  
  "${MINGW_PACKAGE_PREFIX}-python-click"
  "${MINGW_PACKAGE_PREFIX}-python-click-default-group"
  "${MINGW_PACKAGE_PREFIX}-python-colour"
  "${MINGW_PACKAGE_PREFIX}-python-numpy"
  "${MINGW_PACKAGE_PREFIX}-python-pillow"
  "${MINGW_PACKAGE_PREFIX}-python-scipy"
  "${MINGW_PACKAGE_PREFIX}-python-tqdm"
  "${MINGW_PACKAGE_PREFIX}-python-pydub"
  "${MINGW_PACKAGE_PREFIX}-python-pygments"
  "${MINGW_PACKAGE_PREFIX}-python-rich"
  "${MINGW_PACKAGE_PREFIX}-python-cairo"
  "${MINGW_PACKAGE_PREFIX}-python-manimpango"
  "${MINGW_PACKAGE_PREFIX}-python-networkx"
  "${MINGW_PACKAGE_PREFIX}-python-decorator"
  "${MINGW_PACKAGE_PREFIX}-python-setuptools"
  "${MINGW_PACKAGE_PREFIX}-python-watchdog"
  "${MINGW_PACKAGE_PREFIX}-python-moderngl"
  "${MINGW_PACKAGE_PREFIX}-python-moderngl-window"
  "${MINGW_PACKAGE_PREFIX}-mapbox-earcut"
  "${MINGW_PACKAGE_PREFIX}-python-cloup"
  "${MINGW_PACKAGE_PREFIX}-python-requests"
)
optdepends=("${MINGW_PACKAGE_PREFIX}-texlive-most: For LaTeX support")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
source=("${_realname}-${pkgver}.tar.gz"::"https://github.com/ManimCommunity/${_realname}/releases/download/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha512sums=('f197926f39f48b363ba7e089fec9f05e684bca0efa22668dcf488fc523356aa333e93f1489bd899f370d10f7a71505376535f4eca422ed9cf6f5358f5a6805c5')

prepare() {
  rm -rf python-build-${CARCH} | true
  cp -r "${_realname}-${pkgver}" "python-build-${CARCH}"
  cd "python-build-${CARCH}"
  sed -i 's/rich>=6.0,<7.0/rich/' setup.py
  sed -i 's/decorator<5.0.0/decorator/' setup.py
}

build() {  
  msg "Python build for ${CARCH}"
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

package() {
  cd "${srcdir}/python-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  local PREFIX_WIN=$(cygpath -wm ${MINGW_PREFIX})
  # fix python command in files
  for _f in "${pkgdir}${MINGW_PREFIX}"/bin/*.py; do
    sed -i 's/\#\!.*//' $_f
  done
  
  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
  install -Dm644 LICENSE.community "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE.community"
}
